#ifndef LOGCATCLIENT_H
#define LOGCATCLIENT_H

#include <QTcpSocket>
#include <QTimer>
#include "logitem.h"

class LogCatClient : public QTcpSocket
{
    Q_OBJECT
    Q_PROPERTY(bool isConnected MEMBER isConnected NOTIFY isConnectedChanged)
public:
    explicit LogCatClient(QObject *parent = 0);

    void sendData(QByteArray data);
signals:
    void ready();
    void newLog(const LogItem &log);
    void isConnectedChanged();

public slots:
    void start(const QString host, int port);
    void stop(void);
    void reconnect();
    void sendTestMsg(const QString &msg);
private slots:
    void _slotConnected(void);
    void _slotDisConnected(void);
    void handleError(QAbstractSocket::SocketError socketError);
    void readLog(void);
private:
    QByteArray m_dataBuffer;
    QTimer m_timer;
    QString m_host;
    quint16 m_port;
    bool isConnected;
    bool m_running;

};

#endif // LOGCATCLIENT_H
